<?php
class m_public_function extends CI_Model {
	
	function _menu(){
		$sql = "SELECT  child.menus_id , child.menus_label,  child.menus_param, child.menus_url , child.menus_icon , parent.menus_label as parent_label , parent.menus_icon as parent_icon
	FROM s_menus child
	LEFT JOIN s_menus parent ON parent.menus_id = child.menus_parent
	WHERE parent.menus_label is not null
	and child.menus_active = 'y' ORDER BY parent.menus_seq,  child.menus_seq ";
		$query = $this->db->query($sql);
		$result = array();
		foreach($query->result() as $row){
			$result[$row->parent_label][] = $row;
		}
		return $result;
	}
	
	/* all data */
	
	function _cabang(){
		$sql = "SELECT cabang_id, cabang_nama FROM m_cabang ";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
	function _pekerjaan($mandor_id){
		$sql = "SELECT pekerjaan_id, pekerjaan_ket FROM m_pekerjaan ";
        if ($mandor_id != 0){
            $subsql = "SELECT mandor_kemampuan FROM m_mandor WHERE mandor_id = '$mandor_id'";
            $query = $this->db->query($subsql);
            $row = $query->row("mandor_kemampuan");
            
            $sql .= " WHERE pekerjaan_id in ($row)";
        }
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
	function _keuangan(){
		$sql = "SELECT keuangan_id, keuangan_ket FROM m_keuangan ";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
	function _pendanaan(){
		$sql = "SELECT pendanaan_id, pendanaan_ket FROM m_pendanaan ";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
    
	function _proyek(){
		$sql = "SELECT proyek_id, proyek_nama, proyek_kode FROM m_proyek ";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
    
	function _mandor(){
		$sql = "SELECT mandor_id, mandor_nama, mandor_kode FROM m_mandor ";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
    
	function _pembayaran(){
		$sql = "SELECT pembayaran_id, pembayaran_ket FROM m_pembayaran ";
		$query = $this->db->query($sql);
		$result = $query->result();
		return $result;
	}
	
	
}